package com.zhiwang.planet.ui.webview_ultimate.interceptors

import android.text.TextUtils
import android.util.Log
import android.webkit.WebView
import com.zhiwang.planet.ui.WebViewPageHandler
import com.zhiwang.planet.ui.webview_ultimate.InterceptorAdapter
import com.zhiwang.planet.util.Store

class LegacyInterceptor : InterceptorAdapter() {


    override fun onGoBack(handler: WebViewPageHandler, webView: WebView): Boolean {

        val currUrl = webView.url
        //如果是赚钱页面，直接返回
        if (Store.URL_MY_GAME == currUrl || Store.URL_MY_TASK == currUrl)
            handler.closePage()
        else if (webView.canGoBack()) {
            webView.goBack()
            return true
        } else {
            handler.closePage()
            return true
        }

        return false
    }

    private val TAG = "LegacyInterceptor"

    override fun shouldInterceptUrlLoading(webView: WebView, url: String): Boolean {
        webView.loadUrl(url, webViewHeader())

        return false
    }

    override fun onResume(webView: WebView) {
        if (TextUtils.isEmpty(webView.url).not() && Store.URL_MY_GAME == webView.url || Store.URL_MY_TASK == webView.url ||
                Store.URL_LOTTERY == webView.url)
            webView.reload()

    }

}